﻿#ifndef QFILECACHE_H
#define QFILECACHE_H
#include <QMutex>
#include <QFile>
#include <QDateTime>
#include <QMap>
#include <thread>

struct FileCacheObiect{
    QFile file;
    QDateTime lastVisitTime;
};

class QFileCache
{
public:
    static QFileCache* getInstance();

    int writeData(QString filePath,uint64_t seek,char* buffer,int bufferLen);
    int readData(QString filePath,uint64_t seek,char* buffer,int bufferLen);

    int getTimeout() const;
    void setTimeout(int value);

private:
    QFileCache();
    ~QFileCache();
    static QFileCache *instance;
    int timeout; //超时时长 s
    QMutex fileCacheMapMutex;
    QMap<QString,FileCacheObiect*> fileCacheMap;
    void fileCacheRecovery();
    bool fileCacheRecoveryRun;
    std::thread fileCacheRecoveryThread;
};

#endif // QFILECACHE_H
